//
//  SingleSearchView.m
//  SafeFoodManagerDemo
//
//  Created by bob on 2017/11/15.
//  Copyright © 2017年 bob. All rights reserved.
//

#import "SingleSearchView.h"

@interface SingleSearchView()<UISearchBarDelegate>

@property(nonatomic,copy)BeginSearchBlock Cblock;

@property(nonatomic,strong) UISearchBar *searchBar;

@end

@implementation SingleSearchView

-(instancetype)initWithFrame:(CGRect)frame andSearchPloahe:(NSString*)Ploahe andBlock:(BeginSearchBlock)block
{
    if (self=[super initWithFrame:frame]) {
        
        self.backgroundColor=[UIColor whiteColor];
        
        self.searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(5, 0, SCREEN_WIDTH-80, 56)];
        
        self.searchBar.searchBarStyle=UISearchBarStyleMinimal;

        self.searchBar.placeholder=Ploahe;
        
        self.searchBar.delegate=self;
        
        self.searchBar.returnKeyType=UIReturnKeyDone;
        
        [self addSubview:self.searchBar];
        
        UIButton *SearchBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        
        SearchBtn.frame=CGRectMake(SCREEN_WIDTH-70, 12, 60, 32);
        
        [SearchBtn setTitle:@"搜索" forState:UIControlStateNormal];
        
        [SearchBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        SearchBtn.backgroundColor=kColorRGB(0xface48);
        
        SearchBtn.layer.cornerRadius=3.0;
        
        SearchBtn.layer.masksToBounds=YES;
        
        [SearchBtn addTarget:self action:@selector(GotoSearch:) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:SearchBtn];
        
           _Cblock=block;
    }
    
    
    return self;
    
}

-(void)GotoSearch:(UIButton*)sender
{
    _Cblock(self.searchBar.text);
    
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    
    [searchBar resignFirstResponder];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
